/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tp_sd_server.model;

import java.util.Collection;
import java.util.Comparator;

/**
 *
 * @author kill9
 */
public class MaxTreeSet<K> extends java.util.TreeSet<K>{

    private int maxSize=10;



    public MaxTreeSet(int maxSize,Comparator<K> comparator) {
        super(comparator);
        this.maxSize = maxSize;
    }

    @Override
    public boolean add(K e) {
        if(this.size()>=maxSize){
            K k = this.last();
            if(comparator().compare(k, e)<0){
                return false;
            }
            this.remove(k);
        }
        return super.add(e);
    }

}
